home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
demo
/
rotplnnr.lha
/
RouteEdit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-21
|
88KB
|
2,963 lines
// RouteEdit -- edits RoutePlanner files
#include <proto/asl.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/icon.h>
#include <proto/utility.h>
#include <proto/muimaster.h>
#include <proto/intuition.h>
#include <clib/alib_protos.h>
#include <exec/memory.h>
#include <utility/hooks.h>
#include <libraries/mui.h>
#include <libraries/gadtools.h>
#include "RoutePlanner.h"
#include "RouteEdit_rev.h"
#include <dos.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <reg.h>
extern struct Library *MUIMasterBase;
extern struct Library *IconBase;
extern struct Library *UtilityBase;
extern struct IntuitionBase *IntuitionBase;
extern struct Library *AslBase;
void SPrintf(char *outstr, char *fmt, ...);
void AddRouteEntries(APTR list,struct RouteData *rd,ULONG rdcount,
ULONG citynumber);
void RemoveRoute(ULONG routenumber);
void RemoveCity(ULONG citynumber);
void ReLink(void);
BOOL RedoMemory(ULONG NeededCityEntries, ULONG NeededRouteEntries);
void AddCityEntries(APTR list, struct CityData *cd, ULONG CityCount);
BOOL OpenDatabase(char *filename);
BOOL SaveDatabase(char *filename);
ULONG BreakRoute(ULONG rte, ULONG origin);
APTR __saveds __asm constructor(register __a2 APTR pool,
register __a1 struct CityName *entry);
void NullString(char *str, ULONG length);
void SetColumn(struct RouteData *rd,ULONG rdcount,ULONG citynumber);
ULONG InfoRequester(char *filename, BOOL mpr);
void NullString(char *str, ULONG length)
{
ULONG i;
for(i=0;i<length;i++)
str[i]='\0';
}
// Special list constructors and destructors
APTR __saveds __asm constructor(register __a2 APTR pool,
register __a1 struct CityName *entry)
{
struct CityName *cn;
if(cn=malloc(sizeof(struct CityName)))
{
CopyMem(entry,cn,sizeof(struct CityName));
}
return cn;
}
VOID __saveds __asm destructor(register __a2 APTR pool,
register __a1 struct CityName *entry);
VOID __saveds __asm destructor(register __a2 APTR pool,
register __a1 struct CityName *entry)
{
free(entry);
}
LONG __saveds __asm display(register __a2 char **array,
register __a1 struct CityName *cn);
LONG __saveds __asm display(register __a2 char **array,
register __a1 struct CityName *cn)
{
*array=cn->cn_Name;
return 0;
}
LONG __saveds __asm compare(register __a1 struct CityName *cn1,
register __a2 struct CityName *cn2);
LONG __saveds __asm compare(register __a1 struct CityName *cn1,
register __a2 struct CityName *cn2)
{
return(Stricmp(cn1->cn_Name,cn2->cn_Name));
}
struct Hook comphook={{NULL,NULL},&compare,NULL,NULL};
struct Hook consthook={{NULL,NULL},(HOOKFUNC)&constructor,NULL,NULL};
struct Hook desthook={{NULL,NULL},(HOOKFUNC)&destructor,NULL,NULL};
struct Hook disphook={{NULL,NULL},&display,NULL,NULL};
// Route constructors and destructors
APTR __saveds __asm rteconst(register __a2 APTR pool,
register __a1 struct RouteData *entry);
APTR __saveds __asm rteconst(register __a2 APTR pool,
register __a1 struct RouteData *entry)
{
struct RouteName *rn;
if(rn=malloc(sizeof(struct RouteName)))
{
rn->rn_RouteID=entry->RouteID;
SPrintf(rn->rn_Name,"%s (%s, %s)",entry->Hiway,
entry->CityNum[entry->Colm[0]]->CityName,
entry->CityNum[entry->Colm[0]]->StateName);
}
return rn;
}
VOID __saveds __asm rtedest(register __a2 APTR pool,
register __a1 struct CityName *entry);
VOID __saveds __asm rtedest(register __a2 APTR pool,
register __a1 struct CityName *entry)
{
free(entry);
}
LONG __saveds __asm rtedisp(register __a2 char **array,
register __a1 struct RouteName *rn);
LONG __saveds __asm rtedisp(register __a2 char **array,
register __a1 struct RouteName *rn)
{
*array=rn->rn_Name;
return 0;
}
LONG __saveds __asm rtecomp(register __a1 struct RouteName *rn1,
register __a2 struct RouteName *rn2);
LONG __saveds __asm rtecomp(register __a1 struct RouteName *rn1,
register __a2 struct RouteName *rn2)
{
return(Stricmp(rn1->rn_Name,rn2->rn_Name));
}
struct Hook rcomphook={{NULL,NULL},&rtecomp,NULL,NULL};
struct Hook rconsthook={{NULL,NULL},(HOOKFUNC)&rteconst,NULL,NULL};
struct Hook rdesthook={{NULL,NULL},(HOOKFUNC)&rtedest,NULL,NULL};
struct Hook rdisphook={{NULL,NULL},&rtedisp,NULL,NULL};
// General Defines
#define COPYRIGHT VERS" ("DATE") -- Copyright 1994 Chris Lawrence"
BOOL Authenticated;
APTR app=NULL, memptr=NULL, cdptr=NULL, rdptr=NULL, mainwindow=NULL;
struct DiskObject *disko=NULL;
// These two pointers used by memory reallocation system
struct CityData *cd;
struct RouteData *rd;
ULONG cdcount=0,rdcount=0;
struct DataBaseInfo dbi;
struct Registration *reg=NULL;
UWORD MeasureUnits;
void _STD_32767_killapp(void);
void _STD_32767_killapp(void)
{
// SAS/C Autotermination function
// This removes the application using MUI_DisposeObject. It is called
// when the program exits. Normal exits would also save the application
// object.
if(memptr)
free(memptr);
else
{
if(cdptr) free(cdptr);
if(rdptr) free(rdptr);
}
if(disko) FreeDiskObject(disko);
if(app) MUI_DisposeObject(app);
}
APTR KeyPopButton(ULONG img, char key);
APTR KeyPopButton(ULONG img, char key)
{
return (ImageObject,
ImageButtonFrame,
MUIA_ControlChar, key,
MUIA_Image_Spec, img,
MUIA_Image_FontMatch, TRUE,
MUIA_InputMode, MUIV_InputMode_RelVerify,
MUIA_Background, MUII_ButtonBack,
End);
}
#define setinteger(obj,num) set(obj,MUIA_String_Integer,num)
#undef setstring
void setstring(APTR object, char *str);
void setstring(APTR object, char *str)
{
set(object,MUIA_String_Contents,str);
}
void settext(APTR object, char *str);
void settext(APTR object, char *str)
{
set(object,MUIA_Text_Contents,str);
}
#undef KeyButton
APTR KeyButton(char *label, char key);
APTR KeyButton(char *label, char key)
{
return (TextObject,
ButtonFrame,
MUIA_Text_Contents, label,
MUIA_Text_PreParse, MUIX_C,
MUIA_Text_HiChar, key,
MUIA_ControlChar, key,
MUIA_InputMode, MUIV_InputMode_RelVerify,
MUIA_Background, MUII_ButtonBack,
MUIA_Weight, 25,
End);
}
APTR SimpleText(char *text);
APTR SimpleText(char *text)
{
return(TextObject,
TextFrame,
MUIA_Text_Contents, text,
MUIA_InputMode, MUIV_InputMode_None,
MUIA_Background, MUII_TextBack,
End);
}
void ButtonBehave(APTR button, LONG notifyval);
void ButtonBehave(APTR button, LONG notifyval)
{
DoMethod((ULONG *)button,MUIM_Notify,MUIA_Pressed,FALSE,app,2,
MUIM_Application_ReturnID, notifyval);
}
void StringBehave(APTR string, LONG notifyval);
void StringBehave(APTR string, LONG notifyval)
{
DoMethod((ULONG *)string,MUIM_Notify,MUIA_String_Acknowledge,
MUIV_EveryTime, app, 2, MUIM_Application_ReturnID, notifyval);
}
void StringReturn(APTR string, APTR window);
void StringReturn(APTR string, APTR window)
{
DoMethod(string,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
window,3,MUIM_Set,MUIA_Window_ActiveObject,
MUIV_Window_ActiveObject_Next);
}
void CycleBehave(APTR cycle, LONG notifyval);
void CycleBehave(APTR cycle, LONG notifyval)
{
DoMethod((ULONG *)cycle,MUIM_Notify,MUIA_Cycle_Active,
MUIV_EveryTime, app, 2, MUIM_Application_ReturnID, notifyval);
}
BOOL GetFile(char *filename, BOOL saverequest, char *tbar);
BOOL GetFile(char *filename, BOOL saverequest, char *tbar)
{
static char file[40], dir[255], *c;
struct FileRequester *fr;
struct Window *win;
BOOL result;
fr=MUI_AllocAslRequest(ASL_FileRequest,NULL);
if(!fr) return FALSE;
get(mainwindow,MUIA_Window_Window,&win);
set(app,MUIA_Application_Sleep,TRUE);
if(Stricmp(filename,""))
{
strcpy(dir,filename);
c=PathPart(dir);
*c='\0';
c=FilePart(filename);
strcpy(file,c);
}
else
{
strcpy(dir,"");
strcpy(file,"");
}
if(MUI_AslRequestTags(fr,
ASLFR_Window, win,
ASLFR_TitleText, tbar,
ASLFR_Flags1, (saverequest ? FRF_DOSAVEMODE : 0),
ASLFR_RejectIcons, TRUE,
ASLFR_InitialDrawer, dir,
ASLFR_InitialFile, file,
TAG_DONE))
{
strcpy(filename,fr->fr_Drawer);
AddPart(filename,fr->fr_File,255);
result=TRUE;
}
else
{
result=FALSE;
}
set(app,MUIA_Application_Sleep,FALSE);
if(fr) MUI_FreeAslRequest(fr);
return result;
}
// Gadget defines for ChooseCity
#define CANCEL (30)
#define OK (31)
#define STRING (32)
#define CHANGELV (33)
#define ALL (34)
ULONG ChooseCity(struct CityData *cd, ULONG CityCount, ULONG CurrentCity,
char *tbar);
ULONG ChooseCity(struct CityData *cd, ULONG CityCount, ULONG CurrentCity,
char *tbar)
{
// Present requester for choosing a city.
// Return -2 if quit request received.
// Return -1 if canceled
APTR citywindow, LV_Listview, BT_Ok, BT_Cancel, ST_CityName, BT_All;
APTR tempptr;
BOOL going=TRUE, exact;
ULONG sigs, choice, temp, i, found, entries;
static struct CityName *cn;
static char *tmp, cbuf[514], sbuf[128], compstr[256];
set(app,MUIA_Application_Sleep,TRUE);
citywindow=WindowObject,
MUIA_Window_Title, tbar,
MUIA_Window_ScreenTitle, COPYRIGHT,
MUIA_Window_RefWindow, mainwindow,
MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
MUIA_Window_LeftEdge, MUIV_Window_LeftEdge_Moused,
MUIA_Window_TopEdge, MUIV_Window_TopEdge_Moused,
MUIA_Window_Height, MUIV_Window_Height_Default,
MUIA_HelpNode, "CityRequester",
WindowContents,
VGroup,
Child,LV_Listview=ListviewObject,
MUIA_Listview_List, ListObject,
MUIA_List_CompareHook, &comphook,
MUIA_List_ConstructHook, &consthook,
MUIA_List_DestructHook, &desthook,
MUIA_List_DisplayHook, &disphook,
MUIA_List_AdjustWidth, TRUE,
InputListFrame,
End,
MUIA_Listview_MultiSelect, MUIV_Listview_MultiSelect_None,
End,
Child,HGroup,
Child, KeyLLabel2("Search:",'s'),
Child, ST_CityName=KeyString("",70,'s'),
Child, BT_All=KeyButton("All",'l'),
End,
Child,HGroup,
Child, BT_Ok=KeyButton("Ok",'o'),
Child, BT_Cancel=KeyButton("Cancel",'c'),
MUIA_Group_SameWidth, TRUE,
End,
End,
End;
if(citywindow)
{
DoMethod(app,OM_ADDMEMBER,citywindow);
DoMethod(citywindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,CANCEL);
DoMethod(LV_Listview,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
app,2,MUIM_Application_ReturnID,OK);
ButtonBehave(BT_Ok, OK);
ButtonBehave(BT_Cancel, CANCEL);
ButtonBehave(BT_All, ALL);
DoMethod(LV_Listview,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,
app,2,MUIM_Application_ReturnID,CHANGELV);
// Add entries to list & sort them
for(i=0;i<CityCount;i++)
{
cd[i].cd_Dummy=(unsigned char)cd[i].Displayed;
cd[i].Displayed=TRUE;
}
AddCityEntries(LV_Listview,cd,CityCount);
if(CurrentCity==(ULONG)-1)
{
set(LV_Listview,MUIA_List_Active,MUIV_List_Active_Off);
set(BT_Ok,MUIA_Disabled,TRUE);
}
else
{
BOOL found=FALSE;
for(i=0;i<cdcount && !found;i++)
{
DoMethod(LV_Listview,MUIM_List_GetEntry,i,&cn);
if(cn->cn_CityID==CurrentCity)
{
found=TRUE;
set(LV_Listview,MUIA_List_Active,i);
}
}
}
DoMethod(citywindow,MUIM_Window_SetCycleChain,ST_CityName,
LV_Listview,NULL);
set(citywindow,MUIA_Window_DefaultObject,LV_Listview);
set(citywindow,MUIA_Window_ActiveObject,ST_CityName);
set(ST_CityName,MUIA_String_AttachedList,LV_Listview);
StringBehave(ST_CityName,STRING);
set(citywindow,MUIA_Window_Open,TRUE);
DoMethod(LV_Listview,MUIM_List_Jump,MUIV_List_Jump_Active);
while(going)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{ // Can't ignore MUIV_Application_ReturnID_Quit
case MUIV_Application_ReturnID_Quit:
choice=(ULONG)-2;
going=FALSE;
break;
case CANCEL:
choice=(ULONG)-1;
going=FALSE;
break;
case CHANGELV:
get(LV_Listview,MUIA_List_Active,&temp);
set(BT_Ok,MUIA_Disabled,(temp==MUIV_List_Active_Off));
if(temp!=MUIV_List_Active_Off)
{
DoMethod(LV_Listview,MUIM_List_GetEntry,
MUIV_List_GetEntry_Active,&cn);
setstring(ST_CityName,cn->cn_Name);
}
break;
case STRING:
// Do search thingy
get(LV_Listview,MUIA_List_Entries,&entries);
get(ST_CityName,MUIA_String_Contents,&tmp);
strcpy(cbuf,tmp);
set(LV_Listview,MUIA_List_Active,MUIV_List_Active_Off);
if(tmp=strchr(cbuf,','))
{
*tmp++='\0';
while(*tmp==' ') tmp++;
strcpy(sbuf,tmp);
}
else strcpy(sbuf,"");
SPrintf(compstr,"%s#?,# %s#?",cbuf,sbuf);
ParsePatternNoCase(compstr,cbuf,514);
if(Stricmp(compstr,"#?,# #?"))
{
for(found=0,i=0,exact=FALSE;i<entries;i++)
{
DoMethod(LV_Listview,MUIM_List_GetEntry,i,&cn);
if(MatchPatternNoCase(cbuf,cn->cn_Name))
{
cd[cn->cn_CityID].Displayed=TRUE;
found++;
choice=i;
get(ST_CityName,MUIA_String_Contents,&tmp);
if(!Stricmp(tmp,cn->cn_Name))
{
exact=TRUE;
temp=i;
}
}
else
cd[cn->cn_CityID].Displayed=FALSE;
}
}
else
{
for(i=0;i<CityCount;i++)
cd[i].Displayed=TRUE;
found=2;
}
if(found==0)
{
setstring(ST_CityName,"");
MUI_Request(app,citywindow,0,NULL,"_Ok","No cities matched");
set(citywindow,MUIA_Window_ActiveObject,ST_CityName);
}
else if(found==1 || exact)
{
set(LV_Listview,MUIA_List_Active,(exact ? temp : choice));
if(exact)
{
DoMethod(app,MUIM_Application_ReturnID,OK);
set(citywindow,MUIA_Window_ActiveObject,LV_Listview);
}
else
set(citywindow,MUIA_Window_ActiveObject,ST_CityName);
}
else
{
AddCityEntries(LV_Listview,cd,CityCount);
set(citywindow,MUIA_Window_ActiveObject,ST_CityName);
}
break;
case OK:
get(citywindow,MUIA_Window_ActiveObject,&tempptr);
if(tempptr==ST_CityName)
{
DoMethod(app,MUIM_Application_ReturnID,STRING);
}
else
{
DoMethod(LV_Listview,MUIM_List_GetEntry,
MUIV_List_GetEntry_Active,&cn);
if(cn)
{
get(ST_CityName,MUIA_String_Contents,&tmp);
if(!Stricmp(cn->cn_Name,tmp))
{
choice=cn->cn_CityID;
going=FALSE;
}
else
{
DoMethod(app,MUIM_Application_ReturnID,STRING);
}
}
}
break;
case ALL:
for(i=0;i<CityCount;i++)
cd[i].Displayed=TRUE;
AddCityEntries(LV_Listview,cd,CityCount);
set(citywindow,MUIA_Window_ActiveObject,ST_CityName);
break;
}
if(going && sigs) Wait(sigs);
}
for(i=0;i<CityCount;i++)
cd[i].Displayed=(BOOL)cd[i].cd_Dummy;
set(citywindow,MUIA_Window_Open,FALSE);
DoMethod(app,OM_REMMEMBER,citywindow);
MUI_DisposeObject(citywindow);
}
else
MUI_RequestA(app,mainwindow,0,NULL,"_Ok","Couldn't create city requester.",NULL);
set(app,MUIA_Application_Sleep,FALSE);
return(choice);
}
void AddCityEntries(APTR list, struct CityData *cd, ULONG CityCount)
{
ULONG i;
struct CityName cn;
set(list,MUIA_List_Quiet,TRUE);
DoMethod(list,MUIM_List_Clear,NULL);
for(i=0;i<CityCount;i++)
{
if(cd[i].Displayed)
{
cn.cn_CityID=cd[i].CityID;
SPrintf(cn.cn_Name,"%s, %s",cd[i].CityName,cd[i].StateName);
DoMethod(list,MUIM_List_InsertSingle,&cn,MUIV_List_Insert_Sorted);
}
}
set(list,MUIA_List_Quiet,FALSE);
}
UWORD ConvertDist(UWORD srcDist, UWORD srcUnits, UWORD destUnits);
UWORD ConvertDist(UWORD srcDist, UWORD srcUnits, UWORD destUnits)
{
ULONG work;
if(srcUnits==UNITS_ENGLISH && destUnits==UNITS_METRIC)
{
work=(srcDist*16093)+8047;
work/=10000;
}
else if(srcUnits==UNITS_METRIC && destUnits==UNITS_ENGLISH)
{
work=(srcDist*10000)+5000;
work/=16093;
}
else work=srcDist;
return (UWORD)work;
}
ULONG EditRoute(ULONG RouteNumber, ULONG OriginCity, char *tbar);
BOOL EditCity(ULONG id, char *title);
ULONG ModifiedProjectRequest(char *message);
ULONG ModifiedProjectRequest(char *message)
{
return (ULONG)MUI_Request(app,mainwindow,0,NULL,"C_ontinue|*_Cancel",
message);
}
#define NC_CANCEL (100L)
#define NC_OK (101L)
BOOL EditCity(ULONG id, char *title)
{
APTR twindow, ST_CityName, ST_StateName, BT_Ok, BT_Cancel;
APTR CB_IsJunction, CB_CoordsExist, ST_Latitude, ST_Longitude;
BOOL mpr=FALSE, going=TRUE;
ULONG sigs, i;
char *str, cbuf[20];
set(app,MUIA_Application_Sleep,TRUE);
twindow=WindowObject,
MUIA_Window_Title, title,
MUIA_Window_ScreenTitle, COPYRIGHT,
MUIA_Window_RefWindow, mainwindow,
MUIA_Window_NoMenus, TRUE,
MUIA_Window_ID, 100,
MUIA_HelpNode, "EditCity",
WindowContents,
VGroup,
Child, ColGroup(2),
Child, KeyLabel2("City:",'c'),
Child, ST_CityName=KeyString(cd[id].CityName,32,'c'),
Child, KeyLabel2("State:",'s'),
Child, ST_StateName=KeyString(cd[id].StateName,22,'s'),
End,
Child, MUI_MakeObject(MUIO_HBar,0),
Child, VGroup,
Child, ColGroup(4),
Child, HSpace(0),
Child, CB_IsJunction=KeyCheckMark(cd[id].Intersection,'i'),
Child, KeyLLabel1("Intersection",'i'),
Child, HSpace(0),
Child, HSpace(0),
Child, CB_CoordsExist=KeyCheckMark(cd[id].CoordsExist,'u'),
Child, KeyLLabel1("Use Coordinates",'u'),
Child, HSpace(0),
End,
Child, ColGroup(2),
Child, Label2("Latitude:"),
Child, ST_Latitude=StringObject,
StringFrame,
MUIA_String_MaxLen, 8,
MUIA_String_Contents, "",
MUIA_String_Accept, ".0123456789-",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_Disabled, !cd[id].CoordsExist,
End,
Child, Label2("Longitude:"),
Child, ST_Longitude=StringObject,
StringFrame,
MUIA_String_MaxLen, 8,
MUIA_String_Contents, "",
MUIA_String_Accept, ".0123456789-",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_Disabled, !cd[id].CoordsExist,
End,
End,
End,
Child, HGroup,
Child, BT_Ok=KeyButton("Ok",'o'),
Child, BT_Cancel=KeyButton("Cancel",'<'),
MUIA_Group_SameWidth, TRUE,
End,
End,
End;
if(twindow)
{
DoMethod(app,OM_ADDMEMBER,twindow);
if(cd[id].CoordsExist)
{
sprintf(cbuf,"%-3.3f",cd[id].CityPos.latitude);
setstring(ST_Latitude,cbuf);
sprintf(cbuf,"%-3.3f",cd[id].CityPos.longitude);
setstring(ST_Longitude,cbuf);
}
DoMethod(CB_CoordsExist,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
app,6,MUIM_MultiSet,MUIA_Disabled,MUIV_NotTriggerValue,
ST_Latitude,ST_Longitude,NULL);
DoMethod(twindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,
MUIM_Application_ReturnID,NC_CANCEL);
StringReturn(ST_CityName,twindow);
StringReturn(ST_Latitude,twindow);
StringReturn(ST_Longitude,twindow);
StringBehave(ST_StateName,NC_OK);
ButtonBehave(BT_Ok,NC_OK);
ButtonBehave(BT_Cancel,NC_CANCEL);
DoMethod(twindow,MUIM_Window_SetCycleChain,ST_CityName,ST_StateName,
ST_Latitude,ST_Longitude,NULL);
set(twindow,MUIA_Window_ActiveObject,ST_CityName);
set(twindow,MUIA_Window_Open,TRUE);
while(going)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{ // Can't ignore MUIV_Application_ReturnID_Quit
case MUIV_Application_ReturnID_Quit:
mpr=FALSE;
going=FALSE;
DoMethod(app,MUIM_Application_ReturnID,
MUIV_Application_ReturnID_Quit);
break;
case NC_OK:
get(ST_CityName,MUIA_String_Contents,&str);
strcpy(cd[id].CityName,str);
get(ST_StateName,MUIA_String_Contents,&str);
strcpy(cd[id].StateName,str);
get(CB_IsJunction,MUIA_Selected,&i);
cd[id].Intersection=i;
get(CB_CoordsExist,MUIA_Selected,&i);
cd[id].CoordsExist=i;
if(i)
{
get(ST_Latitude,MUIA_String_Contents,&str);
cd[id].CityPos.latitude=atof(str);
get(ST_Longitude,MUIA_String_Contents,&str);
cd[id].CityPos.longitude=atof(str);
}
mpr=TRUE;
going=FALSE;
break;
case NC_CANCEL:
mpr=FALSE;
going=FALSE;
break;
}
if(going && sigs) Wait(sigs);
}
set(twindow,MUIA_Window_Open,FALSE);
DoMethod(app,OM_REMMEMBER,twindow);
MUI_DisposeObject(twindow);
}
set(app,MUIA_Application_Sleep,FALSE);
return mpr;
}
#define ABOUT (1L)
#define HIDE (2L)
#define QUIT MUIV_Application_ReturnID_Quit
#define SAVE (3L)
#define SAVEAS (4L)
#define OPEN (5L)
#define NEW (6L)
#define INFO (7L)
#define SAVEASLOCKED (8L)
#define ADDROUTE (10L)
#define CHANGEROUTE (11L)
#define REMOVEROUTE (12L)
#define ADDCITY (13L)
#define REMOVECITY (14L)
#define EDITCITY (15L)
#define JUMP (16L)
#define BREAK (17L)
#define ALLCITIES (18L)
#define LVMOVE (20L)
#define RETURNCITY (21L)
#define MPRTRUE (28L)
#define UPDATEAVAIL (29L)
#define ABANDONPROJECT (1UL)
#define SAVEPROJECT (2UL)
#define CANCELPROJECT (0UL)
struct NewMenu mainmenu[]={
NM_TITLE, "Project", NULL, 0L, 0L, NULL,
NM_ITEM, "New", "N", 0L, 0L, (APTR)NEW,
NM_ITEM, "Open...", "O", 0L, 0L, (APTR)OPEN,
NM_ITEM, NM_BARLABEL, NULL, 0L, 0L, NULL,
NM_ITEM, "Save", "S", 0L, 0L, (APTR)SAVE,
NM_ITEM, "Save As...", "A", 0L, 0L, (APTR)SAVEAS,
NM_ITEM, "Save As Locked...", "L", 0L, 0L, (APTR)SAVEASLOCKED,
NM_ITEM, NM_BARLABEL, NULL, 0L, 0L, NULL,
NM_ITEM, "About...", "?", 0L, 0L, (APTR)ABOUT,
NM_ITEM, "Information...","I", 0L, 0L, (APTR)INFO,
NM_ITEM, NM_BARLABEL, NULL, 0L, 0L, NULL,
NM_ITEM, "Hide", "H", 0L, 0L, (APTR)HIDE,
NM_ITEM, "Quit", "Q", 0L, 0L, (APTR)QUIT,
NM_END, NULL, NULL, 0L, 0L, NULL
};
#define DisableInactive(object,i)\
set(object,MUIA_Disabled,i==MUIV_List_Active_Off)
#define SetTBar { SPrintf(tbar,"RouteEdit: %s%s",(mpr ? "* " : ""),\
(Stricmp(DBase,"") ? DBase : "Untitled")); \
set(mainwindow,MUIA_Window_Title,tbar); }
void main(int argc, char **argv)
// Main user interface code
// Includes choose route requester
{
STATIC char DBase[256]="", tbar[256]="";
APTR mainmenustrip, LV_Route, BT_AddCity;
APTR BT_RemoveCity, LV_City, ST_City, BT_AddRoute, BT_EditRoute;
APTR BT_RemoveRoute, BT_EditCity, tptr, BT_Jump, BT_Break, BT_All;
BPTR file;
BOOL going=TRUE, exact;
BOOL mpr=FALSE, ok;
ULONG sigs, temp, i, found, entries, choice;
static struct CityName *cn;
static struct RouteName *rn;
static char *tmp, cbuf[514], sbuf[128], compstr[256];
if(!argc)
{
argc=_WBArgc;
argv=_WBArgv;
}
app=ApplicationObject,
MUIA_Application_Title, "RouteEdit",
MUIA_Application_Version, "$VER: "VERS" ("DATE")",
MUIA_Application_Copyright, "Copyright (C) 1994 Chris Lawrence",
MUIA_Application_Author, "Chris Lawrence",
MUIA_Application_Description,"Highway Route Editor for RoutePlanner",
MUIA_Application_Base, "ROUTEEDIT",
MUIA_Application_SingleTask, FALSE,
MUIA_Application_DiskObject,
disko=GetDiskObjectNew("PROGDIR:RouteEdit"),
MUIA_Application_HelpFile, "PROGDIR:RouteEdit.guide",
// MUIA_Application_Commands, COMMANDS,
SubWindow,
mainwindow=WindowObject,
MUIA_Window_Title, "RouteEdit: Untitled",
MUIA_Window_ID, 'REDT',
MUIA_Window_Menustrip,
mainmenustrip=MUI_MakeObject(MUIO_MenustripNM,mainmenu,0),
MUIA_Window_ScreenTitle, COPYRIGHT,
MUIA_HelpNode, "MainWindow",
WindowContents,
HGroup,
Child, VGroup,
MUIA_HelpNode, "CitiesHalf",
GroupFrameT("Cities"),
MUIA_Weight, 100,
Child, LV_City=ListviewObject,
MUIA_Listview_Input, TRUE,
MUIA_Listview_List, ListObject,
MUIA_List_CompareHook, &comphook,
MUIA_List_ConstructHook, &consthook,
MUIA_List_DestructHook, &desthook,
MUIA_List_DisplayHook, &disphook,
MUIA_List_AdjustWidth, TRUE,
InputListFrame,
End,
End,
Child, HGroup,
Child, KeyLLabel2("Search:",'s'),
Child, ST_City=StringObject,
StringFrame,
MUIA_String_AttachedList, LV_City,
MUIA_String_MaxLen, 100,
MUIA_ControlChar, 's',
End,
Child, BT_All=KeyButton("All",'l'),
End,
Child, HGroup,
MUIA_HelpNode, "CityButtons",
Child, BT_AddCity=KeyButton("Add...",'d'),
Child, BT_EditCity=KeyButton("Change...",'c'),
Child, BT_RemoveCity=KeyButton("Remove",'m'),
MUIA_Group_SameWidth, TRUE,
End,
End,
Child, VGroup,
MUIA_Weight, 100,
Child, VGroup,
MUIA_HelpNode, "RoutesHalf",
GroupFrameT("Connections"),
Child, LV_Route=ListviewObject,
MUIA_Listview_Input, TRUE,
MUIA_Listview_List, ListObject,
MUIA_List_CompareHook, &rcomphook,
MUIA_List_ConstructHook, &rconsthook,
MUIA_List_DestructHook, &rdesthook,
MUIA_List_DisplayHook, &rdisphook,
MUIA_List_AdjustWidth, TRUE,
InputListFrame,
End,
End,
Child, HGroup,
MUIA_HelpNode, "RouteButtons",
Child, BT_AddRoute=KeyButton("Add...",'a'),
Child, BT_EditRoute=KeyButton("Edit...",'e'),
Child, BT_Break=KeyButton("Break...",'b'),
Child, BT_Jump=KeyButton("Jump",'j'),
Child, BT_RemoveRoute=KeyButton("Remove",'r'),
MUIA_Group_SameWidth, TRUE,
End,
End,
End,
End,
End,
End;
if(!app)
{
MUI_Request(NULL,NULL,0L,"RouteEdit","Ok","Could not create application.");
exit(20);
}
DoMethod(mainwindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,QUIT);
DoMethod(LV_Route,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
app,2,MUIM_Application_ReturnID,CHANGEROUTE);
DoMethod(LV_City,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,
app,2,MUIM_Application_ReturnID,LVMOVE);
DoMethod(LV_Route,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,
app,2,MUIM_Application_ReturnID,UPDATEAVAIL);
set(ST_City,MUIA_String_AttachedList,LV_City);
ButtonBehave(BT_AddRoute, ADDROUTE);
ButtonBehave(BT_EditRoute, CHANGEROUTE);
ButtonBehave(BT_RemoveRoute, REMOVEROUTE);
ButtonBehave(BT_AddCity, ADDCITY);
ButtonBehave(BT_RemoveCity, REMOVECITY);
ButtonBehave(BT_All, ALLCITIES);
StringBehave(ST_City, RETURNCITY);
DoMethod(BT_EditCity,MUIM_Notify,MUIA_Pressed,FALSE,
mainwindow,3,MUIM_Set,MUIA_Window_ActiveObject,LV_City);
ButtonBehave(BT_EditCity, EDITCITY);
ButtonBehave(BT_Jump, JUMP);
ButtonBehave(BT_Break, BREAK);
DoMethod(LV_City,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
app,2,MUIM_Application_ReturnID,EDITCITY);
DoMethod(mainwindow,MUIM_Window_SetCycleChain,LV_City,ST_City,
LV_Route,NULL);
file=Open("PROGDIR:RouteEdit.key",MODE_OLDFILE);
if(!file)
{
file=Open("s:RouteEdit.key",MODE_OLDFILE);
if(!file)
{
file=Open("s:Global_CTS.key",MODE_OLDFILE);
}
}
if(file)
{
reg=malloc(sizeof(struct Registration));
if(reg)
{
if(FRead(file,reg,sizeof(struct Registration),1))
{
if(!(Authenticated=Authenticate(reg,CTS_ROUTEEDIT)))
{
free(reg);
reg=NULL;
}
}
else
{
free(reg);
reg=NULL;
}
}
Close(file);
}
if(!reg || !Authenticated)
DoMethod(mainwindow,MUIM_Window_SetMenuState,SAVEASLOCKED,FALSE);
set(mainwindow,MUIA_Window_Open,TRUE);
get(mainwindow,MUIA_Window_Open,&i);
if(!i)
{
MUI_Request(app,NULL,0,NULL,"_Ok","Couldn't open main window.");
exit(20);
}
DoMethod(app,MUIM_Application_ReturnID,UPDATEAVAIL);
if(argc>1)
{
set(app,MUIA_Application_Sleep,TRUE);
if(OpenDatabase(argv[argc-1]))
{
strcpy(DBase,argv[argc-1]);
mpr=FALSE;
SetTBar;
for(i=0;i<cdcount;i++)
cd[i].Displayed=TRUE;
setstring(ST_City,"");
AddCityEntries(LV_City,cd,cdcount);
if(rdcount)
{
MeasureUnits=rd[0].Units;
}
}
else
{
MUI_Request(app,mainwindow,0,NULL,"_Ok",
"Unable to open database %s.",argv[argc-1]);
}
set(app,MUIA_Application_Sleep,FALSE);
}
while(going)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{ // Can't ignore MUIV_Application_ReturnID_Quit
case 0:
break;
case MUIV_Application_ReturnID_Quit:
get(app,MUIA_Application_ForceQuit,&temp);
if(mpr && !temp)
i=ModifiedProjectRequest("Do you want to quit without\n"
"saving the current database?");
else i=ABANDONPROJECT;
if(i==ABANDONPROJECT)
{
going=FALSE;
}
else if(i==SAVEPROJECT)
{
DoMethod(app,MUIM_Application_ReturnID,SAVE);
DoMethod(app,MUIM_Application_ReturnID,QUIT);
}
break;
case ABOUT:
get(mainwindow,MUIA_Window_ActiveObject,&i);
if(reg && Authenticated)
{
MUI_Request(app,mainwindow,0,NULL,(char *)"_Ok",
(char *)MUIX_C""
VERS" ("DATE")\n\n"
"Map Editor for RoutePlanner\n"
"© 1994 Chris Lawrence\n"
"All rights reserved\n\n"
"Registered to:\n"
"%s (%s)\n\n"
"This application uses MUI\n"
"MUI is © 1993-94 Stefan Stuntz\n\n"
"Compiled on "__DATE__,
reg->Name,reg->EMail);
}
else
{
MUI_Request(app,mainwindow,0,NULL,(char *)"_Ok",
(char *)MUIX_C""
VERS" ("DATE")\n\n"
"Map Editor for RoutePlanner\n"
"© 1994 Chris Lawrence\n"
"All rights reserved\n\n"
"This application uses MUI\n"
"MUI is © 1993-94 Stefan Stuntz\n\n"
"Compiled on "__DATE__);
}
set(mainwindow,MUIA_Window_ActiveObject,i);
break;
case INFO:
if(Stricmp(DBase,""))
{
tmp=DBase;
}
else
{
tmp="Untitled";
}
get(mainwindow,MUIA_Window_ActiveObject,&i);
set(app,MUIA_Application_Sleep,TRUE);
temp=InfoRequester(tmp,mpr);
if(temp!=QUIT)
{
mpr=temp;
SetTBar;
set(mainwindow,MUIA_Window_ActiveObject,i);
}
else
DoMethod(app,MUIM_Application_ReturnID,QUIT);
set(app,MUIA_Application_Sleep,FALSE);
break;
case HIDE:
set(app,MUIA_Application_Iconified,TRUE);
break;
case NEW:
if(mpr)
i=ModifiedProjectRequest("Do you want to start a new database\n"
"without saving the current one?");
else i=ABANDONPROJECT;
if(i==ABANDONPROJECT)
{
if(RedoMemory(0,0))
{
strcpy(DBase,"");
SetTBar;
cdcount=0;
rdcount=0;
ReLink();
mpr=FALSE;
AddCityEntries(LV_City,cd,cdcount);
DoMethod(app,MUIM_Application_ReturnID,UPDATEAVAIL);
}
}
else if(i==SAVEPROJECT)
{
DoMethod(app,MUIM_Application_ReturnID,SAVE);
DoMethod(app,MUIM_Application_ReturnID,NEW);
}
break;
case OPEN:
if(mpr)
i=ModifiedProjectRequest("Do you want to open another file\n"
"without saving the current one?");
else i=ABANDONPROJECT;
if(i==ABANDONPROJECT)
{
strcpy(cbuf,DBase);
if(GetFile(cbuf,FALSE,"Open database..."))
{
set(app,MUIA_Application_Sleep,TRUE);
if(OpenDatabase(cbuf))
{
strcpy(DBase,cbuf);
mpr=FALSE;
SetTBar;
for(i=0;i<cdcount;i++)
cd[i].Displayed=TRUE;
setstring(ST_City,"");
AddCityEntries(LV_City,cd,cdcount);
DoMethod(app,MUIM_Application_ReturnID,UPDATEAVAIL);
if(rdcount)
{
MeasureUnits=rd[0].Units;
}
}
else
{
MUI_Request(app,mainwindow,0,NULL,"_Ok",
"Unable to open database %s.",cbuf);
}
set(app,MUIA_Application_Sleep,FALSE);
}
}
else if(i==SAVEPROJECT)
{
DoMethod(app,MUIM_Application_ReturnID,SAVE);
DoMethod(app,MUIM_Application_ReturnID,OPEN);
}
break;
case SAVEAS:
// Alters filename, does a SAVE call
if(GetFile(DBase,TRUE,"Save database as..."))
{
SetTBar;
DoMethod(app,MUIM_Application_ReturnID,SAVE);
}
break;
case SAVE:
if(!Stricmp(DBase,""))
{
DoMethod(app,MUIM_Application_ReturnID,SAVEAS);
}
else
{
set(app,MUIA_Application_Sleep,TRUE);
dbi.dbi_AuthorCode=(ULONG)~0;
dbi.dbi_Security=DoFunkyThing(cdcount+rdcount+dbi.dbi_AuthorCode+
StringSum(dbi.dbi_Author)+StringSum(dbi.dbi_EMail));
if(SaveDatabase(DBase))
{
mpr=FALSE;
SetTBar;
}
else
{
MUI_Request(app,mainwindow,0,NULL,"_Ok",
"Unable to save database.");
}
set(app,MUIA_Application_Sleep,FALSE);
}
break;
case SAVEASLOCKED:
// Alters filename, does a SAVE call
if(reg && Authenticated &&
GetFile(DBase,TRUE,"Save locked database as..."))
{
set(app,MUIA_Application_Sleep,TRUE);
SetTBar;
dbi.dbi_AuthorCode=(ULONG)reg->ActualNumber;
strcpy(dbi.dbi_Author,reg->Name);
strcpy(dbi.dbi_EMail,reg->EMail);
dbi.dbi_Security=DoFunkyThing(cdcount+rdcount+dbi.dbi_AuthorCode+
StringSum(dbi.dbi_Author)+StringSum(dbi.dbi_EMail));
if(SaveDatabase(DBase))
{
mpr=FALSE;
SetTBar;
}
else
{
MUI_Request(app,mainwindow,0,NULL,"_Ok",
"Unable to save database.");
}
set(app,MUIA_Application_Sleep,FALSE);
}
break;
case ADDCITY:
if(RedoMemory(cdcount+1,rdcount))
{
ReLink();
get(LV_City,MUIA_List_Active,&i);
memset(&cd[cdcount],'\0',sizeof(cd[cdcount]));
cd[cdcount].Displayed=TRUE;
cd[cdcount].CityID=cdcount;
set(mainwindow,MUIA_Window_Sleep,TRUE);
ok=EditCity(cdcount,"Add new city...");
if(ok)
{
struct CityName tname;
tname.cn_CityID=cdcount;
SPrintf(tname.cn_Name,"%s, %s",cd[cdcount].CityName,
cd[cdcount].StateName);
setstring(ST_City,tname.cn_Name);
DoMethod(LV_City,MUIM_List_InsertSingle,&tname,
MUIV_List_Insert_Sorted);
get(LV_City,MUIA_List_Entries,&entries);
for(i=0;i<entries;i++)
{
DoMethod(LV_City,MUIM_List_GetEntry,i,&cn);
if(cn->cn_CityID==cdcount) temp=i;
}
cdcount++;
ReLink();
set(LV_City,MUIA_List_Active,temp);
mpr=TRUE;
SetTBar;
}
else
{
RedoMemory(cdcount,rdcount);
ReLink();
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,
&cn);
if(cn) SetColumn(rd,rdcount,cn->cn_CityID);
}
set(mainwindow,MUIA_Window_Sleep,FALSE);
}
break;
case EDITCITY:
get(mainwindow,MUIA_Window_ActiveObject,&tptr);
if(tptr==ST_City)
{
DoMethod(app,MUIM_Application_ReturnID,RETURNCITY);
}
else
{
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(cn)
{
ok=EditCity(cn->cn_CityID,"Edit city...");
if(ok)
{
struct CityName tname;
found=cn->cn_CityID;
set(LV_City,MUIA_List_Quiet,TRUE);
DoMethod(LV_City,MUIM_List_Remove,MUIV_List_Remove_Active);
tname.cn_CityID=found;
SPrintf(tname.cn_Name,"%s, %s",cd[found].CityName,
cd[found].StateName);
setstring(ST_City,tname.cn_Name);
DoMethod(LV_City,MUIM_List_InsertSingle,&tname,
MUIV_List_Insert_Sorted);
get(LV_City,MUIA_List_Entries,&entries);
for(i=0;i<entries;i++)
{
DoMethod(LV_City,MUIM_List_GetEntry,i,&cn);
if(cn->cn_CityID==found) temp=i;
}
set(LV_City,MUIA_List_Active,temp);
set(LV_City,MUIA_List_Quiet,FALSE);
mpr=TRUE;
SetTBar;
}
}
}
break;
case REMOVECITY:
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(cn)
{
set(mainwindow,MUIA_Window_Sleep,TRUE);
get(LV_City,MUIA_List_Active,&i);
RemoveCity(cn->cn_CityID);
AddCityEntries(LV_City,cd,cdcount);
set(LV_City,MUIA_List_Active,i);
set(mainwindow,MUIA_Window_Sleep,FALSE);
mpr=TRUE;
SetTBar;
}
break;
case ADDROUTE:
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(cn)
{
if(RedoMemory(cdcount,rdcount+1))
{
memset(&rd[rdcount],'\0',sizeof(rd[rdcount]));
rd[rdcount].Colm[0]=1;
rd[rdcount].CityID[0]=cn->cn_CityID;
rd[rdcount].CityID[1]=(UWORD)-1;
rd[rdcount].SpeedCode=USE_SPEED;
rd[rdcount].Units=MeasureUnits;
rd[rdcount].RouteID=rdcount;
temp=EditRoute(rdcount,cn->cn_CityID,"Add route segment");
if(temp==(ULONG)-3)
{
ReLink();
DoMethod(app,MUIM_Application_ReturnID,QUIT);
}
else if(temp==(ULONG)-2)
{
ULONG count,num;
found=rdcount;
rdcount++;
ReLink();
AddRouteEntries(LV_Route,rd,rdcount,cn->cn_CityID);
get(LV_Route,MUIA_List_Entries,&count);
for(i=0;i<count;i++)
{
DoMethod(LV_Route,MUIM_List_GetEntry,i,&rn);
if(rn->rn_RouteID==found) num=i;
}
set(LV_Route,MUIA_List_Active,num);
mpr=TRUE;
SetTBar;
}
else
{
RedoMemory(cdcount,rdcount);
ReLink();
SetColumn(rd,rdcount,cn->cn_CityID);
}
}
}
break;
case CHANGEROUTE:
DoMethod(LV_Route,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&rn);
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(rn && cn)
{
get(LV_Route,MUIA_List_Active,&i);
temp=EditRoute(rn->rn_RouteID,cn->cn_CityID,
"Edit route segment");
if(temp==(ULONG)-3)
{
DoMethod(app,MUIM_Application_ReturnID,QUIT);
}
else if(temp==(ULONG)-2)
{
ULONG count,num;
ReLink();
AddRouteEntries(LV_Route,rd,rdcount,cn->cn_CityID);
found=rn->rn_RouteID;
get(LV_Route,MUIA_List_Entries,&count);
for(i=0;i<count;i++)
{
DoMethod(LV_Route,MUIM_List_GetEntry,i,&rn);
if(rn->rn_RouteID==found) num=i;
}
set(LV_Route,MUIA_List_Active,num);
mpr=TRUE;
SetTBar;
}
else
{
SetColumn(rd,rdcount,cn->cn_CityID);
}
}
break;
case BREAK:
DoMethod(LV_Route,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&rn);
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(rn && cn)
{
get(LV_Route,MUIA_List_Active,&i);
temp=BreakRoute(rn->rn_RouteID,cn->cn_CityID);
if(temp==(ULONG)-3)
{
DoMethod(app,MUIM_Application_ReturnID,QUIT);
}
else if(temp==(ULONG)-2)
{
ULONG count,num;
ReLink();
AddRouteEntries(LV_Route,rd,rdcount,cn->cn_CityID);
found=rn->rn_RouteID;
get(LV_Route,MUIA_List_Entries,&count);
for(i=0;i<count;i++)
{
DoMethod(LV_Route,MUIM_List_GetEntry,i,&rn);
if(rn->rn_RouteID==found) num=i;
}
set(LV_Route,MUIA_List_Active,num);
mpr=TRUE;
SetTBar;
}
else
{
SetColumn(rd,rdcount,cn->cn_CityID);
}
}
break;
case REMOVEROUTE:
DoMethod(LV_Route,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&rn);
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(rn && cn)
{
get(LV_Route,MUIA_List_Active,&i);
RemoveRoute(rn->rn_RouteID);
AddRouteEntries(LV_Route,rd,rdcount,cn->cn_CityID);
set(LV_Route,MUIA_List_Active,i);
mpr=TRUE;
SetTBar;
}
break;
case JUMP:
DoMethod(LV_Route,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&rn);
if(rn)
{
set(mainwindow,MUIA_Window_Sleep,TRUE);
i=rd[rn->rn_RouteID].Colm[0];
found=rd[rn->rn_RouteID].CityID[i];
if(!cd[found].Displayed)
{
cd[found].Displayed=TRUE;
AddCityEntries(LV_City,cd,cdcount);
}
get(LV_City,MUIA_List_Entries,&entries);
for(i=0;i<entries;i++)
{
DoMethod(LV_City,MUIM_List_GetEntry,i,&cn);
if(cn->cn_CityID==found) temp=i;
}
nnset(LV_City,MUIA_List_Active,temp);
DoMethod(LV_City,MUIM_List_GetEntry,temp,&cn);
if(cn)
setstring(ST_City,cn->cn_Name);
else
setstring(ST_City,"");
temp=rn->rn_RouteID;
AddRouteEntries(LV_Route,rd,rdcount,found);
found=temp;
temp=MUIV_List_Active_Top;
get(LV_Route,MUIA_List_Entries,&entries);
for(i=0;i<entries;i++)
{
DoMethod(LV_Route,MUIM_List_GetEntry,i,&rn);
if(rn->rn_RouteID==found) temp=i;
}
nnset(LV_Route,MUIA_List_Active,temp);
set(mainwindow,MUIA_Window_Sleep,FALSE);
}
break;
case LVMOVE:
get(LV_Route,MUIA_List_Entries,&entries);
DoMethod(LV_Route,MUIM_List_GetEntry,0,&rn);
DoMethod(LV_City,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&cn);
if(rn && cn)
{
temp=(rd[rn->rn_RouteID].CityID[1-rd[rn->rn_RouteID].Colm[0]]==cn->cn_CityID);
}
else temp=FALSE;
if(!temp && cn)
{
setstring(ST_City,cn->cn_Name);
AddRouteEntries(LV_Route,rd,rdcount,cn->cn_CityID);
}
DoMethod(app,MUIM_Application_ReturnID,UPDATEAVAIL);
break;
case RETURNCITY:
// Do search thingy
for(i=0;i<cdcount;i++)
cd[i].cd_Dummy=cd[i].Displayed;
get(ST_City,MUIA_String_Contents,&tmp);
strcpy(cbuf,tmp);
set(LV_City,MUIA_List_Active,MUIV_List_Active_Off);
if(tmp=strchr(cbuf,','))
{
*tmp++='\0';
while(*tmp==' ') tmp++;
strcpy(sbuf,tmp);
}
else strcpy(sbuf,"");
SPrintf(compstr,"%s#?,# %s#?",cbuf,sbuf);
ParsePatternNoCase(compstr,cbuf,514);
get(LV_City,MUIA_List_Entries,&entries);
if(Stricmp(compstr,"#?,# #?"))
{
for(found=0,i=0,exact=FALSE;i<entries;i++)
{
DoMethod(LV_City,MUIM_List_GetEntry,i,&cn);
if(cn)
{
if(MatchPatternNoCase(cbuf,cn->cn_Name))
{
cd[cn->cn_CityID].Displayed=TRUE;
found++;
choice=i;
get(ST_City,MUIA_String_Contents,&tmp);
if(!Stricmp(tmp,cn->cn_Name))
{
temp=i;
exact=TRUE;
}
}
else
cd[cn->cn_CityID].Displayed=FALSE;
}
}
}
else
{
for(i=0;i<cdcount;i++)
cd[i].Displayed=TRUE;
found=2;
}
if(found==0)
{
setstring(ST_City,"");
MUI_Request(app,mainwindow,0,NULL,"_Ok","No cities matched");
set(mainwindow,MUIA_Window_ActiveObject,ST_City);
set(LV_City,MUIA_List_Active,MUIV_List_Active_Off);
for(i=0;i<cdcount;i++)
cd[i].Displayed=cd[i].cd_Dummy;
}
else if(found==1 || exact)
{
set(LV_City,MUIA_List_Active,(exact ? temp : choice));
if(exact)
set(mainwindow,MUIA_Window_ActiveObject,LV_City);
else
set(mainwindow,MUIA_Window_ActiveObject,ST_City);
for(i=0;i<cdcount;i++)
cd[i].Displayed=cd[i].cd_Dummy;
}
else
{
AddCityEntries(LV_City,cd,cdcount);
set(mainwindow,MUIA_Window_ActiveObject,ST_City);
DoMethod(app,MUIM_Application_ReturnID,UPDATEAVAIL);
}
break;
case UPDATEAVAIL:
get(LV_City,MUIA_List_Active,&i);
DisableInactive(BT_AddRoute,i);
DisableInactive(BT_RemoveCity,i);
DisableInactive(BT_EditCity,i);
if(i==MUIV_List_Active_Off)
{
DoMethod(LV_Route,MUIM_List_Clear,NULL);
set(BT_Jump,MUIA_Disabled,TRUE);
set(BT_EditRoute,MUIA_Disabled,TRUE);
set(BT_RemoveRoute,MUIA_Disabled,TRUE);
set(BT_Break,MUIA_Disabled,TRUE);
}
else
{
get(LV_Route,MUIA_List_Active,&i);
DisableInactive(BT_Jump,i);
DisableInactive(BT_EditRoute,i);
DisableInactive(BT_RemoveRoute,i);
DisableInactive(BT_Break,i);
}
get(LV_Route,MUIA_List_Entries,&i);
set(LV_Route,MUIA_Disabled,(i==0));
break;
case ALLCITIES:
set(mainwindow,MUIA_Window_Sleep,TRUE);
for(i=0;i<cdcount;i++)
cd[i].Displayed=TRUE;
AddCityEntries(LV_City,cd,cdcount);
set(mainwindow,MUIA_Window_ActiveObject,ST_City);
DoMethod(app,MUIM_Application_ReturnID,UPDATEAVAIL);
set(mainwindow,MUIA_Window_Sleep,FALSE);
break;
}
if(going && sigs) sigs=Wait(sigs | SIGBREAKF_CTRL_C);
if(sigs & SIGBREAKF_CTRL_C) going=FALSE;
}
if(reg) free(reg);
set(mainwindow,MUIA_Window_Open,FALSE);
exit(0);
}
void RemoveCity(ULONG citynumber)
{
char tmp;
ULONG rnum;
for(rnum=0;rnum<rdcount;rnum++)
{
BOOL thiscity=FALSE;
for(tmp=0;tmp<2;tmp++)
{
if(rd[rnum].CityID[tmp]>citynumber)
rd[rnum].CityID[tmp]--;
else if(rd[rnum].CityID[tmp]==citynumber)
thiscity=TRUE;
}
if(thiscity)
{
RemoveRoute(rnum);
rnum--;
}
}
for(rnum=0;rnum<cdcount;rnum++)
{
if(cd[rnum].CityID>citynumber)
(cd[rnum].CityID)--;
if(&cd[rnum]>&cd[citynumber])
memcpy(&cd[rnum-1],&cd[rnum],sizeof(struct CityData));
}
RedoMemory(cdcount-1,rdcount);
cdcount--;
ReLink();
}
void RemoveRoute(ULONG routenumber)
{
ULONG rnum;
for(rnum=0;rnum<rdcount;rnum++)
{
if(rd[rnum].RouteID>routenumber)
(rd[rnum].RouteID)--;
if(&rd[rnum]>&rd[routenumber])
memcpy(&rd[rnum-1],&rd[rnum],sizeof(struct RouteData));
}
RedoMemory(cdcount,rdcount-1);
rdcount--;
ReLink();
}
void AddRouteEntries(APTR list,struct RouteData *rd,ULONG rdcount,
ULONG citynumber)
{
ULONG i;
char tmp;
set(list,MUIA_List_Quiet,TRUE);
DoMethod(list,MUIM_List_Clear,NULL);
for(i=0;i<rdcount;i++)
{
BOOL found=FALSE;
for(tmp=0;tmp<2;tmp++)
if(rd[i].CityID[tmp]==citynumber)
{
found=TRUE;
rd[i].Colm[0]=1-tmp;
}
if(found)
DoMethod(list,MUIM_List_InsertSingle,&rd[i],MUIV_List_Insert_Sorted);
}
set(list,MUIA_List_Quiet,FALSE);
}
void SetColumn(struct RouteData *rd,ULONG rdcount,ULONG citynumber)
{
ULONG i;
char tmp;
for(i=0;i<rdcount;i++)
{
for(tmp=0;tmp<2;tmp++)
if(rd[i].CityID[tmp]==citynumber)
{
rd[i].Colm[0]=1-tmp;
}
}
}
APTR DLabel(const char *string);
APTR DLabel(const char *string)
{
APTR tmp;
tmp=TextObject,
StringFrame,
MUIA_FramePhantomHoriz, TRUE,
MUIA_Text_SetMin, FALSE,
MUIA_Text_SetMax, FALSE,
MUIA_FixWidthTxt, "km/h",
MUIA_Text_PreParse, MUIX_L,
MUIA_Text_Contents, string,
MUIA_InputMode, MUIV_InputMode_None,
End;
return tmp;
}
#define ER_FROM (200L)
#define ER_TO (201L)
#define ER_SPEED (202L)
#define ER_MEASUREUNITS (203L)
#define ER_OK (204L)
#define ER_CANCEL (205L)
#define ER_DISTANCE (206L)
char *unitlabels[]={ "Metric", "English", NULL };
char *distlabels[]={ "km", "mi", NULL };
char *speedlabels[]={ "km/h", "mph", "min", NULL };
char *rteclasses[]={
"Other (speed)",
"Other (time)",
"Rural Interstate",
"Suburban Interstate",
"Urban Interstate",
"Rural Highway (4 Lane)",
"Rural Highway (2 Lane)",
"Suburban Highway",
"Suburban Road",
"Urban Road",
"Rural Interstate (55)",
"Metro Interstate",
"Autoroute (Canada)",
"Main Highway (Canada)",
"Rural Motorway (UK)",
"Suburban Motorway (UK)",
"Urban Motorway (UK)",
"Primary 4 Lane (UK)",
"Primary 2 Lane (UK)",
"Other Route (UK)",
NULL};
ULONG EditRoute(ULONG RouteNumber, ULONG OriginCity, char *tbar)
// Edit route segments
//
// Retval: -1 = cancel; -2 = ok; -3 = quit received;
{
ULONG retval=(ULONG)-1, i, sigs, tmp, tmp2;
APTR editwindow, BT_From, BT_To, ST_Distance, CY_Speed, ST_Speed;
APTR BT_Ok, BT_Cancel, CY_MeasureUnits, ST_Hiway;
APTR TX_From, TX_To, TX_DistUnits, TX_SpeedUnits, ST_FromExit, ST_ToExit;
BOOL going=TRUE;
UWORD fromcity, tocity;
char fside, tside, *str;
static char tbuf[256];
editwindow=WindowObject,
MUIA_Window_Title, tbar,
MUIA_Window_ScreenTitle, COPYRIGHT,
MUIA_Window_ID, 200,
MUIA_Window_NoMenus, TRUE,
MUIA_HelpNode, "EditRoute",
WindowContents,
VGroup,
Child,VGroup,
GroupFrameT("Route"),
Child,ColGroup(4),
Child, BT_From=KeyButton("From...",'f'),
Child, TX_From=SimpleText(""),
Child, Label2("Exit:"),
Child, ST_FromExit=String("",6),
Child, BT_To=KeyButton("To...",'t'),
Child, TX_To=SimpleText(""),
Child, Label2("Exit:"),
Child, ST_ToExit=String("",6),
End,
Child, MUI_MakeObject(MUIO_HBar,0),
Child, ColGroup(3),
Child, KeyLabel2("Name:",'n'),
Child, ST_Hiway=KeyString("",32,'n'),
Child, HSpace(0),
Child, KeyLabel2("Units:",'u'),
Child, CY_MeasureUnits=KeyCycle(unitlabels,'u'),
Child, HSpace(0),
Child, KeyLabel2("Distance:",'d'),
Child, ST_Distance=StringObject,
StringFrame,
MUIA_String_Accept, "0123456789",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_String_MaxLen, 5,
MUIA_ControlChar, 'd',
End,
Child, TX_DistUnits=DLabel(""),
Child, KeyLabel2("Grade:",'g'),
Child, CY_Speed=KeyCycle(rteclasses,'g'),
Child, HSpace(0),
Child, HSpace(0),
Child,ST_Speed=StringObject,
StringFrame,
MUIA_String_Accept, "0123456789",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_String_MaxLen, 5,
End,
Child, TX_SpeedUnits=DLabel(""),
End,
End,
Child, HGroup,
Child, BT_Ok=KeyButton("Ok",'o'),
Child, BT_Cancel=KeyButton("Cancel",'c'),
MUIA_Group_SameWidth, TRUE,
End,
End,
End;
if(editwindow)
{
set(app,MUIA_Application_Sleep,TRUE);
DoMethod(app,OM_ADDMEMBER,editwindow);
DoMethod(editwindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,ER_CANCEL);
ButtonBehave(BT_To, ER_TO);
ButtonBehave(BT_From, ER_FROM);
ButtonBehave(BT_Ok, ER_OK);
ButtonBehave(BT_Cancel, ER_CANCEL);
CycleBehave(CY_Speed, ER_SPEED);
CycleBehave(CY_MeasureUnits, ER_MEASUREUNITS);
setcycle(CY_MeasureUnits, rd[RouteNumber].Units);
setcycle(CY_Speed, rd[RouteNumber].SpeedCode);
setstring(ST_Hiway, rd[RouteNumber].Hiway);
set(ST_Distance,MUIA_String_Integer,rd[RouteNumber].Distance);
if(rd[RouteNumber].SpeedCode<2)
{
set(ST_Speed,MUIA_String_Integer,rd[RouteNumber].Speed);
}
else
{
set(ST_Speed,MUIA_Disabled,TRUE);
}
if(rd[RouteNumber].SpeedCode==USE_TIME)
{
settext(TX_SpeedUnits, speedlabels[2]);
}
else
{
settext(TX_SpeedUnits, speedlabels[rd[RouteNumber].Units]);
}
tside=rd[RouteNumber].Colm[0];
fside=1-tside;
fromcity=rd[RouteNumber].CityID[fside];
tocity=rd[RouteNumber].CityID[tside];
if(fromcity!=(UWORD)-1)
{
SPrintf(tbuf,"%s, %s",cd[fromcity].CityName,cd[fromcity].StateName);
settext(TX_From,tbuf);
setstring(ST_FromExit,rd[RouteNumber].Exits[fside]);
}
if(tocity!=(UWORD)-1)
{
SPrintf(tbuf,"%s, %s",cd[tocity].CityName,cd[tocity].StateName);
settext(TX_To,tbuf);
setstring(ST_ToExit,rd[RouteNumber].Exits[tside]);
}
set(BT_Ok,MUIA_Disabled,(fromcity==(UWORD)-1 || tocity==(UWORD)-1));
settext(TX_DistUnits, distlabels[rd[RouteNumber].Units]);
DoMethod(editwindow,MUIM_Window_SetCycleChain,ST_Hiway,
CY_MeasureUnits,ST_Distance,CY_Speed,ST_Speed,ST_FromExit,ST_ToExit,
NULL);
MeasureUnits=rd[RouteNumber].Units;
set(editwindow,MUIA_Window_Open,TRUE);
get(editwindow,MUIA_Window_Open,&i);
if(i)
{
set(editwindow,MUIA_Window_ActiveObject,ST_Hiway);
while(going)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{ // Can't ignore MUIV_Application_ReturnID_Quit
case MUIV_Application_ReturnID_Quit:
retval=(ULONG)-3;
going=FALSE;
break;
case ER_CANCEL:
retval=(ULONG)-1;
going=FALSE;
break;
case ER_OK:
// Some stuff here
get(ST_Speed,MUIA_String_Integer,&tmp);
get(ST_Distance,MUIA_String_Integer,&tmp2);
get(CY_Speed,MUIA_Cycle_Active,&i);
if((i>USE_TIME || tmp) && tmp2)
{
rd[RouteNumber].SpeedCode=i;
if(i<=USE_TIME)
{
rd[RouteNumber].Speed=tmp;
}
else
rd[RouteNumber].Speed=0;
rd[RouteNumber].CityID[fside]=fromcity;
rd[RouteNumber].CityID[tside]=tocity;
rd[RouteNumber].Distance=tmp2;
get(ST_Hiway,MUIA_String_Contents,&str);
strcpy(rd[RouteNumber].Hiway,str);
get(ST_FromExit,MUIA_String_Contents,&str);
strcpy(rd[RouteNumber].Exits[fside],str);
get(ST_ToExit,MUIA_String_Contents,&str);
strcpy(rd[RouteNumber].Exits[tside],str);
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
rd[RouteNumber].Units=i;
retval=(ULONG)-2;
going=FALSE;
}
else if(tmp2)
MUI_Request(app,editwindow,0,NULL,"_Ok",
"You must enter a speed or time.");
else
MUI_Request(app,editwindow,0,NULL,"_Ok",
"You must enter a distance.");
break;
case ER_FROM:
i=ChooseCity(cd,cdcount,fromcity,"Choose `from' city...");
if(i==(ULONG)-2)
{
retval=(ULONG)-3;
going=FALSE;
}
else if(i!=(ULONG)-1 && i==tocity)
{
MUI_Request(app,editwindow,0,NULL,"_Ok",
"Can't make `from' city same as `to' city.");
}
else if(i!=(ULONG)-1)
{
fromcity=i;
SPrintf(tbuf,"%s, %s",cd[fromcity].CityName,
cd[fromcity].StateName);
settext(TX_From,tbuf);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1));
}
break;
case ER_TO:
i=ChooseCity(cd,cdcount,tocity,"Choose `to' city...");
if(i==(ULONG)-2)
{
retval=(ULONG)-3;
going=FALSE;
}
else if(i!=(ULONG)-1 && i==fromcity)
{
MUI_Request(app,editwindow,0,NULL,"_Ok",
"Can't make `to' city same as `from' city.");
}
else if(i!=(ULONG)-1)
{
tocity=i;
SPrintf(tbuf,"%s, %s",cd[tocity].CityName,
cd[tocity].StateName);
settext(TX_To,tbuf);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1));
}
break;
case ER_SPEED:
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
get(CY_Speed, MUIA_Cycle_Active, &tmp);
set(ST_Speed, MUIA_Disabled, (tmp>USE_TIME));
if(tmp==USE_TIME)
settext(TX_SpeedUnits, speedlabels[2]);
else
settext(TX_SpeedUnits, speedlabels[i]);
break;
case ER_MEASUREUNITS:
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
get(CY_Speed, MUIA_Cycle_Active, &tmp);
settext(TX_DistUnits, distlabels[i]);
if(tmp==USE_TIME)
settext(TX_SpeedUnits, speedlabels[2]);
else
settext(TX_SpeedUnits, speedlabels[i]);
if(i!=MeasureUnits)
{
ULONG tval;
get(ST_Distance, MUIA_String_Integer, &tval);
tval=ConvertDist(tval,MeasureUnits,i);
set(ST_Distance, MUIA_String_Integer, tval);
if(tmp!=USE_TIME)
{
get(ST_Speed, MUIA_String_Integer, &tval);
tval=ConvertDist(tval,MeasureUnits,i);
set(ST_Speed, MUIA_String_Integer, tval);
}
MeasureUnits=i;
}
break;
}
if(going && sigs) Wait(sigs);
}
}
else
MUI_Request(app,mainwindow,0,NULL,"_Ok","Couldn't open edit window.");
set(editwindow,MUIA_Window_Open,FALSE);
DoMethod(app,OM_REMMEMBER,editwindow);
MUI_DisposeObject(editwindow);
set(app,MUIA_Application_Sleep,FALSE);
}
else
MUI_Request(app,mainwindow,0,NULL,"_Ok","Couldn't create edit window.");
return retval;
}
#define BR_FROM (300L)
#define BR_TO (301L)
#define BR_VIA (302L)
#define BR_MEASUREUNITS (303L)
#define BR_OK (304L)
#define BR_CANCEL (305L)
#define BR_SPEED1 (306L)
#define BR_SPEED2 (307L)
#define BR_DIST1 (308L)
#define BR_DIST2 (309L)
ULONG BreakRoute(ULONG rte, ULONG origin)
// Break route segments
//
// Retval: -1 = cancel; -2 = ok; -3 = quit received;
{
ULONG retval=(ULONG)-1, i, i2, sigs, tmp, tmp2;
UWORD distance, fromcity, tocity, viacity;
APTR editwindow, BT_From, BT_To, ST_Distance1, CY_Speed1, ST_Speed1;
APTR BT_Ok, BT_Cancel, CY_MeasureUnits, ST_Hiway, BT_BreakPoint;
APTR TX_BreakPoint, ST_BreakExit;
APTR TX_From, TX_To, TX_Dist1Units, TX_Speed1Units, ST_FromExit, ST_ToExit;
APTR ST_Distance2, CY_Speed2, ST_Speed2, TX_Dist2Units, TX_Speed2Units;
APTR CB_Lock1, CB_Lock2;
BOOL going=TRUE;
char fside, tside, *str;
static char tbuf[256];
if(!RedoMemory(cdcount,rdcount+1))
{
MUI_Request(app,mainwindow,0,NULL,"_Ok","Couldn't open breakpoint window.");
return retval;
}
viacity=(UWORD)-1;
editwindow=WindowObject,
MUIA_Window_Title, "Break route segment",
MUIA_Window_ScreenTitle, COPYRIGHT,
MUIA_Window_ID, 300,
MUIA_Window_NoMenus, TRUE,
MUIA_HelpNode, "BreakRoute",
WindowContents,
VGroup,
Child,VGroup,
Child,ColGroup(4),
Child, BT_From=KeyButton("From...",'f'),
Child, TX_From=SimpleText(""),
Child, Label2("Exit:"),
Child, ST_FromExit=String("",6),
Child, BT_BreakPoint=KeyButton("Via...",'v'),
Child, TX_BreakPoint=SimpleText(""),
Child, Label2("Exit:"),
Child, ST_BreakExit=String("",6),
Child, BT_To=KeyButton("To...",'t'),
Child, TX_To=SimpleText(""),
Child, Label2("Exit:"),
Child, ST_ToExit=String("",6),
End,
Child, MUI_MakeObject(MUIO_HBar,0),
Child, ColGroup(2),
Child, KeyLabel2("Name:",'n'),
Child, ST_Hiway=KeyString("",32,'n'),
Child, KeyLabel2("Units:",'u'),
Child, CY_MeasureUnits=KeyCycle(unitlabels,'u'),
End,
Child, HGroup,
Child, ColGroup(3),
GroupFrameT("`From' to midpoint"),
Child, KeyLabel2("Distance:",'d'),
Child, HGroup,
Child, CB_Lock1=CheckMark(TRUE),
Child, LLabel1("Link"),
Child, ST_Distance1=StringObject,
StringFrame,
MUIA_String_Accept, "0123456789",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_String_MaxLen, 5,
MUIA_ControlChar, 'd',
End,
End,
Child, TX_Dist1Units=DLabel(""),
Child, KeyLabel2("Grade:",'g'),
Child, CY_Speed1=KeyCycle(rteclasses,'g'),
Child, HSpace(0),
Child, HSpace(0),
Child,ST_Speed1=StringObject,
StringFrame,
MUIA_String_Accept, "0123456789",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_String_MaxLen, 5,
End,
Child, TX_Speed1Units=DLabel(""),
End,
Child, ColGroup(3),
GroupFrameT("`To' to midpoint"),
Child, Label2("Distance:"),
Child, HGroup,
Child, CB_Lock2=CheckMark(TRUE),
Child, LLabel1("Link"),
Child, ST_Distance2=StringObject,
StringFrame,
MUIA_String_Accept, "0123456789",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_String_MaxLen, 5,
End,
End,
Child, TX_Dist2Units=DLabel(""),
Child, Label2("Grade:"),
Child, CY_Speed2=Cycle(rteclasses),
Child, HSpace(0),
Child, HSpace(0),
Child,ST_Speed2=StringObject,
StringFrame,
MUIA_String_Accept, "0123456789",
MUIA_String_Format, MUIV_String_Format_Right,
MUIA_String_MaxLen, 5,
End,
Child, TX_Speed2Units=DLabel(""),
End,
End,
End,
Child, HGroup,
Child, BT_Ok=KeyButton("Ok",'o'),
Child, BT_Cancel=KeyButton("Cancel",'c'),
MUIA_Group_SameWidth, TRUE,
End,
End,
End;
if(editwindow)
{
set(app,MUIA_Application_Sleep,TRUE);
DoMethod(app,OM_ADDMEMBER,editwindow);
DoMethod(editwindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,BR_CANCEL);
DoMethod(CY_Speed1,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
CY_Speed2,3,MUIM_Set,MUIA_Cycle_Active,MUIV_TriggerValue);
DoMethod(ST_Speed1,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
ST_Speed2,3,MUIM_Set,MUIA_String_Contents,MUIV_TriggerValue);
ButtonBehave(BT_To, BR_TO);
ButtonBehave(BT_From, BR_FROM);
ButtonBehave(BT_BreakPoint, BR_VIA);
ButtonBehave(BT_Ok, BR_OK);
ButtonBehave(BT_Cancel, BR_CANCEL);
CycleBehave(CY_Speed1, BR_SPEED1);
CycleBehave(CY_Speed2, BR_SPEED2);
CycleBehave(CY_MeasureUnits, BR_MEASUREUNITS);
StringBehave(ST_Distance1, BR_DIST1);
StringBehave(ST_Distance2, BR_DIST2);
setcycle(CY_MeasureUnits, rd[rte].Units);
setcycle(CY_Speed1, rd[rte].SpeedCode);
setstring(ST_Hiway, rd[rte].Hiway);
distance=rd[rte].Distance;
if(rd[rte].SpeedCode<2)
{
set(ST_Speed1,MUIA_String_Integer,rd[rte].Speed);
}
else
{
set(ST_Speed1,MUIA_Disabled,TRUE);
set(ST_Speed2,MUIA_Disabled,TRUE);
}
if(rd[rte].SpeedCode==USE_TIME)
{
settext(TX_Speed1Units, speedlabels[2]);
}
else
{
settext(TX_Speed1Units, speedlabels[rd[rte].Units]);
}
tside=rd[rte].Colm[0];
fside=1-tside;
fromcity=rd[rte].CityID[fside];
tocity=rd[rte].CityID[tside];
SPrintf(tbuf,"%s, %s",cd[fromcity].CityName,cd[fromcity].StateName);
settext(TX_From,tbuf);
setstring(ST_FromExit,rd[rte].Exits[fside]);
SPrintf(tbuf,"%s, %s",cd[tocity].CityName,cd[tocity].StateName);
settext(TX_To,tbuf);
setstring(ST_ToExit,rd[rte].Exits[tside]);
set(BT_Ok,MUIA_Disabled,TRUE);
settext(TX_Dist1Units, distlabels[rd[rte].Units]);
settext(TX_Dist2Units, distlabels[rd[rte].Units]);
DoMethod(editwindow,MUIM_Window_SetCycleChain,ST_Hiway,
CY_MeasureUnits,CB_Lock1,ST_Distance1,CY_Speed1,ST_Speed1,
CB_Lock2,ST_Distance2,CY_Speed2,ST_Speed2,ST_FromExit,
ST_BreakExit,ST_ToExit,NULL);
MeasureUnits=rd[rte].Units;
set(editwindow,MUIA_Window_Open,TRUE);
get(editwindow,MUIA_Window_Open,&i);
if(i)
{
set(editwindow,MUIA_Window_ActiveObject,ST_Hiway);
while(going)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{ // Can't ignore MUIV_Application_ReturnID_Quit
case MUIV_Application_ReturnID_Quit:
retval=(ULONG)-3;
going=FALSE;
RedoMemory(cdcount,rdcount);
break;
case BR_CANCEL:
retval=(ULONG)-1;
going=FALSE;
RedoMemory(cdcount,rdcount);
break;
case BR_OK:
// Some stuff here
get(CY_Speed1,MUIA_Cycle_Active,&i);
get(ST_Speed1,MUIA_String_Integer,&tmp);
get(CY_Speed2,MUIA_Cycle_Active,&i2);
get(ST_Speed2,MUIA_String_Integer,&tmp2);
if((i>USE_TIME || tmp) && (i2>USE_TIME || tmp2))
{
rd[rte].SpeedCode=i;
if(i<=USE_TIME)
{
rd[rte].Speed=tmp;
}
else
rd[rte].Speed=0;
rd[rdcount].SpeedCode=i2;
if(i<=USE_TIME)
{
rd[rdcount].Speed=tmp2;
}
else
rd[rdcount].Speed=0;
rd[rdcount].RouteID=rdcount;
rd[rte].CityID[fside]=fromcity;
rd[rte].CityID[tside]=viacity;
rd[rdcount].CityID[0]=viacity;
rd[rdcount].CityID[1]=tocity;
get(ST_Distance1,MUIA_String_Integer,&i);
rd[rte].Distance=i;
get(ST_Distance2,MUIA_String_Integer,&i);
rd[rdcount].Distance=i;
get(CY_Speed2,MUIA_Cycle_Active,&i);
rd[rdcount].SpeedCode=i;
get(ST_Hiway,MUIA_String_Contents,&str);
strcpy(rd[rte].Hiway,str);
strcpy(rd[rdcount].Hiway,str);
get(ST_FromExit,MUIA_String_Contents,&str);
strcpy(rd[rte].Exits[fside],str);
get(ST_BreakExit,MUIA_String_Contents,&str);
strcpy(rd[rte].Exits[tside],str);
strcpy(rd[rdcount].Exits[0],str);
get(ST_ToExit,MUIA_String_Contents,&str);
strcpy(rd[rdcount].Exits[1],str);
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
rd[rte].Units=i;
rd[rdcount].Units=i;
retval=(ULONG)-2;
going=FALSE;
rdcount++;
}
else
MUI_Request(app,editwindow,0,NULL,"_Ok",
"You must specify speeds or times.");
break;
case BR_FROM:
i=ChooseCity(cd,cdcount,fromcity,"Choose `from' city...");
if(i==(ULONG)-2)
{
retval=(ULONG)-3;
going=FALSE;
}
else if(i!=(ULONG)-1 && (i==tocity || i==viacity))
{
MUI_Request(app,editwindow,0,NULL,"_Ok",
"Can't make `from' city same\nas `to' or `via' city.");
}
else if(i!=(ULONG)-1)
{
fromcity=i;
SPrintf(tbuf,"%s, %s",cd[fromcity].CityName,
cd[fromcity].StateName);
settext(TX_From,tbuf);
get(ST_Distance1,MUIA_String_Integer,&tmp);
get(ST_Distance2,MUIA_String_Integer,&tmp2);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1 ||
viacity==(UWORD)-1 || !tmp || !tmp2));
}
break;
case BR_TO:
i=ChooseCity(cd,cdcount,tocity,"Choose `to' city...");
if(i==(ULONG)-2)
{
retval=(ULONG)-3;
going=FALSE;
}
else if(i!=(ULONG)-1 && (i==fromcity || i==viacity))
{
MUI_Request(app,editwindow,0,NULL,"_Ok",
"Can't make `to' city same\nas `from' or `via' city.");
}
else if(i!=(ULONG)-1)
{
tocity=i;
SPrintf(tbuf,"%s, %s",cd[tocity].CityName,
cd[tocity].StateName);
settext(TX_To,tbuf);
get(ST_Distance1,MUIA_String_Integer,&tmp);
get(ST_Distance2,MUIA_String_Integer,&tmp2);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1 ||
viacity==(UWORD)-1 || !tmp || !tmp2));
}
break;
case BR_VIA:
i=ChooseCity(cd,cdcount,viacity,"Choose breakpoint...");
if(i==(ULONG)-2)
{
retval=(ULONG)-3;
going=FALSE;
}
else if(i!=(ULONG)-1 && (i==tocity || i==fromcity))
{
MUI_Request(app,editwindow,0,NULL,"_Ok",
"Can't make `via' city same\nas `to' or `from' city.");
}
else if(i!=(ULONG)-1)
{
viacity=i;
SPrintf(tbuf,"%s, %s",cd[viacity].CityName,
cd[viacity].StateName);
settext(TX_BreakPoint,tbuf);
get(ST_Distance1,MUIA_String_Integer,&tmp);
get(ST_Distance2,MUIA_String_Integer,&tmp2);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1 ||
viacity==(UWORD)-1 || !tmp || !tmp2));
}
break;
case BR_SPEED1:
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
get(CY_Speed1, MUIA_Cycle_Active, &tmp);
set(ST_Speed1, MUIA_Disabled, (tmp>USE_TIME));
if(tmp==USE_TIME)
settext(TX_Speed1Units, speedlabels[2]);
else
settext(TX_Speed1Units, speedlabels[i]);
break;
case BR_SPEED2:
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
get(CY_Speed2, MUIA_Cycle_Active, &tmp);
set(ST_Speed2, MUIA_Disabled, (tmp>USE_TIME));
if(tmp==USE_TIME)
settext(TX_Speed2Units, speedlabels[2]);
else
settext(TX_Speed2Units, speedlabels[i]);
break;
case BR_DIST1:
get(CB_Lock1,MUIA_Selected,&i);
if(i)
{
get(ST_Distance1,MUIA_String_Integer,&i);
tmp=ConvertDist(distance,rd[rte].Units,MeasureUnits);
i=(i>tmp ? tmp : i);
set(ST_Distance1,MUIA_String_Integer,i);
set(ST_Distance2,MUIA_String_Integer,tmp-i);
}
get(ST_Distance1,MUIA_String_Integer,&tmp);
get(ST_Distance2,MUIA_String_Integer,&tmp2);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1 ||
viacity==(UWORD)-1 || !tmp || !tmp2));
break;
case BR_DIST2:
get(CB_Lock2,MUIA_Selected,&i);
if(i)
{
get(ST_Distance2,MUIA_String_Integer,&i);
tmp=ConvertDist(distance,rd[rte].Units,MeasureUnits);
i=(i>tmp ? tmp : i);
set(ST_Distance2,MUIA_String_Integer,i);
set(ST_Distance1,MUIA_String_Integer,tmp-i);
}
get(ST_Distance1,MUIA_String_Integer,&tmp);
get(ST_Distance2,MUIA_String_Integer,&tmp2);
set(BT_Ok,MUIA_Disabled,
(fromcity==(UWORD)-1 || tocity==(UWORD)-1 ||
viacity==(UWORD)-1 || !tmp || !tmp2));
break;
case BR_MEASUREUNITS:
get(CY_MeasureUnits,MUIA_Cycle_Active,&i);
get(CY_Speed1, MUIA_Cycle_Active, &tmp);
get(CY_Speed2, MUIA_Cycle_Active, &tmp2);
settext(TX_Dist1Units, distlabels[i]);
settext(TX_Dist2Units, distlabels[i]);
if(tmp==USE_TIME)
settext(TX_Speed1Units, speedlabels[2]);
else
settext(TX_Speed1Units, speedlabels[i]);
if(tmp2==USE_TIME)
settext(TX_Speed2Units, speedlabels[2]);
else
settext(TX_Speed2Units, speedlabels[i]);
if(i!=MeasureUnits)
{
ULONG tval;
get(ST_Distance1, MUIA_String_Integer, &tval);
tval=ConvertDist(tval,MeasureUnits,i);
set(ST_Distance1, MUIA_String_Integer, tval);
get(ST_Distance2, MUIA_String_Integer, &tval);
tval=ConvertDist(tval,MeasureUnits,i);
set(ST_Distance2, MUIA_String_Integer, tval);
if(tmp!=USE_TIME)
{
get(ST_Speed1, MUIA_String_Integer, &tval);
tval=ConvertDist(tval,MeasureUnits,i);
set(ST_Speed1, MUIA_String_Integer, tval);
}
if(tmp2!=USE_TIME)
{
get(ST_Speed2, MUIA_String_Integer, &tval);
tval=ConvertDist(tval,MeasureUnits,i);
set(ST_Speed2, MUIA_String_Integer, tval);
}
MeasureUnits=i;
}
break;
}
if(going && sigs) Wait(sigs);
}
}
else
MUI_Request(app,mainwindow,0,NULL,"_Ok","Couldn't open break window.");
set(editwindow,MUIA_Window_Open,FALSE);
DoMethod(app,OM_REMMEMBER,editwindow);
MUI_DisposeObject(editwindow);
set(app,MUIA_Application_Sleep,FALSE);
}
else
MUI_Request(app,mainwindow,0,NULL,"_Ok","Couldn't create break window.");
ReLink();
return retval;
}
#define IR_OK (400)
#define IR_CANCEL (401)
ULONG InfoRequester(char *filename, BOOL mpr)
{
APTR infowindow, ST_Name, ST_EMail, TX_Cities, TX_Routes;
APTR TX_GfxMem, TX_OtherMem, BT_Ok, BT_Cancel;
char *str, tbuf[100];
int i, sigs;
BOOL going=TRUE;
ULONG retval;
retval=mpr;
infowindow=WindowObject,
MUIA_Window_Title, "Information",
MUIA_Window_ScreenTitle, COPYRIGHT,
MUIA_Window_ID, 400,
MUIA_Window_NoMenus, TRUE,
MUIA_HelpNode, "DBaseInfo",
WindowContents,
VGroup,
Child, ColGroup(2),
Child, Label1("Database:"),
Child, SimpleText(filename),
Child, Label1("Cities:"),
Child, TX_Cities=SimpleText(""),
Child, Label1("Routes:"),
Child, TX_Routes=SimpleText(""),
Child, Label1("Graphics memory:"),
Child, TX_GfxMem=SimpleText(""),
Child, Label1("Other memory:"),
Child, TX_OtherMem=SimpleText(""),
Child, KeyLabel2("Author:",'a'),
Child, ST_Name=KeyString(dbi.dbi_Author,60,'a'),
Child, KeyLabel2("Email address:",'e'),
Child, ST_EMail=KeyString(dbi.dbi_EMail,60,'e'),
End,
Child, HGroup,
MUIA_Group_SameSize, TRUE,
Child, BT_Ok=KeyButton("Ok",'o'),
Child, BT_Cancel=KeyButton("Cancel",'c'),
End,
End,
End;
if(infowindow)
{
DoMethod(app,OM_ADDMEMBER,infowindow);
SPrintf(tbuf,"%ld",cdcount);
settext(TX_Cities,tbuf);
SPrintf(tbuf,"%ld",rdcount);
settext(TX_Routes,tbuf);
SPrintf(tbuf,"%lUk",AvailMem(MEMF_CHIP)/1024);
settext(TX_GfxMem,tbuf);
SPrintf(tbuf,"%lUk",AvailMem(MEMF_FAST)/1024);
settext(TX_OtherMem,tbuf);
StringReturn(ST_Name,infowindow);
StringBehave(ST_EMail,IR_OK);
ButtonBehave(BT_Ok, IR_OK);
ButtonBehave(BT_Cancel, IR_CANCEL);
DoMethod(infowindow,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
app,2,MUIM_Application_ReturnID,IR_CANCEL);
DoMethod(infowindow,MUIM_Window_SetCycleChain,ST_Name,ST_EMail,NULL);
set(infowindow,MUIA_Window_Open,TRUE);
get(infowindow,MUIA_Window_Open,&i);
if(i)
{
while(going)
{
switch(DoMethod(app,MUIM_Application_Input,&sigs))
{
case 0:
break;
case QUIT:
retval=QUIT;
going=FALSE;
break;
case IR_OK:
get(ST_Name,MUIA_String_Contents,&str);
strcpy(dbi.dbi_Author,str);
get(ST_EMail,MUIA_String_Contents,&str);
strcpy(dbi.dbi_EMail,str);
retval=TRUE;
going=FALSE;
break;
case IR_CANCEL:
retval=mpr;
going=FALSE;
break;
}
if(sigs && going) Wait(sigs);
}
set(infowindow,MUIA_Window_Open,FALSE);
}
DoMethod(app,OM_REMMEMBER,infowindow);
MUI_DisposeObject(infowindow);
}
return retval;
}